//
//  SQLiteReader.h
//  WOPrototype
//
//  Created by Olof Millberg on 2010-04-15.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <sqlite3.h>
#import "WorkOrder.h"
#import "WOPerson.h"
#import "WOTimeReport.h"
#import "WorkOrderPreview.h"

@interface SQLiteReader : NSObject 
{
	sqlite3 *database;
	NSString *databasePath;
}

/* Initialization Methods */
- (id) initWithDatabase:(NSString *)databaseName;
- (void) checkAndCreateDatabase:(NSString *)databaseName;

/* Helper Methods */
- (BOOL) doesPersonExist:(WOPerson *)aNewPerson;
- (void) setFilteringParameters:(WorkOrderPreview *)aWorkOrderPreview;
- (WOPerson *) getPersonBySocialID:(NSString *)aSocialID;
- (WOAddress *) getAddressIfExists:(WOAddress *)anAddress;

/* Getter Methods */
- (NSMutableArray *) getWorkOrderPreviewList;
- (NSMutableArray *) getAssignedWorkOrderPreviews;
- (NSMutableArray *) getUnassignedWorkOrderPreviews;

- (NSMutableArray *) getTimeTypes;
- (NSMutableArray *) getStatusTypes;
- (NSMutableArray *) getPriorityTypes;

- (WorkOrder *) getWorkOrderByWorkID:(NSInteger)anID;

- (NSMutableArray *) getAddressBookEntries;
- (NSMutableArray *) getEmployeesByWorkID:(NSInteger)anID;
- (NSMutableArray *) getWorkLeadersByWorkID:(NSInteger)anID;
- (NSMutableArray *) getTimeReportsByWorkID:(NSInteger)anID;
- (NSMutableArray *) getAttachedFilesByWorkID:(NSInteger)anID;
- (NSMutableArray *) getContactPersonsByWorkID:(NSInteger)anID;
- (NSMutableArray *) getChecklistPointsByWorkID:(NSInteger) anID;
- (NSMutableArray *) getHistoryEntriesByStreet:(NSString *)aStreet zipCode:(NSString *)aZipCode;  
- (NSMutableArray *) getTimeIntervalsByWorkID:(NSInteger)anID reportDate:(NSDate *)anEntryDate;

/* Creater Methods */
- (void) createNewWorkOrder:(WorkOrder *)aNewWorkOrder;
- (void) createNewCustomer:(NSString *)aNewCustomer;
- (void) createNewAddress:(WOAddress *)aNewAddress;
- (void) createNewPerson:(WOPerson *)aNewPerson;
- (NSMutableArray *) createChecklistPoints:(WorkOrder *)aWorkOrder;

/* Updater Methods */
- (void) updateWorkOrder:(WorkOrder *)aWorkOrder;
- (void) updateHistoryEntries:(WorkOrder *)aWorkOrder;
- (void) updateTimeReports:(WorkOrder *)aWorkOrder;
- (void) updateTimeIntervalsByTimeReport:(WOTimeReport *)aTimeReport workorder:(WorkOrder *)aWorkOrder;

/* Setter Methods */
- (void) setEmployees:(WorkOrder *)aWorkOrder;
- (void) setTimeReports:(WorkOrder *)aWorkorder;
- (void) setWorkLeaders:(WorkOrder *)aWorkorder;
- (void) setContactPersons:(WorkOrder *)aWorkorder;
- (void) setHistoryEntries:(WorkOrder *)aWorkorder;
- (void) setChecklistPoints:(WorkOrder *)aWorkorder;
- (void) setTimeIntervalsByTimeReport:(WOTimeReport *)aTimeReport workorder:(WorkOrder *)aWorkOrder;

@end